<admintpl file="header" />
<style type="text/css">

</style>
</head>

<body>
<div id="allmap" style="width: 100%;height: 300px;overflow: hidden;margin:0;font-family:'微软雅黑';">

</div>

<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=OkM4ci06ibVrimvizgsIWv0sjASIa7BK&s=1"></script>
<script type="text/javascript">
    // 百度地图API功能
    var route = '<php> echo json_encode($route);</php>';
    route = eval("(" + route + ")");
    var map = new BMap.Map("allmap");
    map.centerAndZoom(new BMap.Point(route.centerLng,route.centerLat), 11);
    map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
    map.enableContinuousZoom();

    var p1 = new BMap.Point(route.shippingLng,route.shippingLat);
    var p2 = new BMap.Point(route.collectLng,route.collectLat);

    var driving = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true}});
    driving.search(p1, p2);
    var myIcon1 = new BMap.Icon("__PUBLIC__/images/start.png", new BMap.Size(30, 30));
    var marker3 = new BMap.Marker(p1, {icon: myIcon1});  // 创建标注
    map.addOverlay(marker3);
    var myIcon2 = new BMap.Icon("__PUBLIC__/images/end.png", new BMap.Size(30, 30));
    var marker4 = new BMap.Marker(p2, {icon: myIcon2});  // 创建标注
    map.addOverlay(marker4);

//    var myDis = new BMapLib.DistanceTool(map);
//    map.addEventListener("load",function(){
//        myDis.open();  //开启鼠标测距
//        //myDis.close();  //关闭鼠标测距大
//    });
    if( 7!= route.status && 1 != route.status) {
        pnroute();
    }


   // pnroute();
    function pnroute(){
        var allOverlay = map.getOverlays();
        if( allOverlay != null )
            map.clearOverlays();

        var p1 = new BMap.Point(route.shippingLng,route.shippingLat);
        var p2 = new BMap.Point(route.collectLng,route.collectLat);

        var driving = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true}});
        driving.search(p1, p2);
        var myIcon1 = new BMap.Icon("__PUBLIC__/images/start.png", new BMap.Size(30, 30));
        var marker3 = new BMap.Marker(p1, {icon: myIcon1});  // 创建标注
        map.addOverlay(marker3);
        var myIcon2 = new BMap.Icon("__PUBLIC__/images/end.png", new BMap.Size(30, 30));
        var marker4 = new BMap.Marker(p2, {icon: myIcon2});  // 创建标注
        map.addOverlay(marker4);

        $.ajax({
            type: "GET",
            async: true,
            url: "{:U('pnRoute',array('order_id'=>$route['order_id']))}",
            dataType: "json",
            success: function(data) {
                var pt = new BMap.Point(data.longitude, data.latitude);
                var myIcon = new BMap.Icon("__PUBLIC__/images/pn.png", new BMap.Size(40, 40));
                var marker2 = new BMap.Marker(pt, {icon: myIcon});  // 创建标注
                map.addOverlay(marker2);
            }
        });
        $.ajax({
            type: "GET",
            async: true,
            url: "{:U('pnRobRouteCounts',array('order_id'=>$route['order_id']))}",
            dataType: "json",
            success: function(data) {
                // console.log(data);

                var dataotherpn = data['otherpn'];
                for (var i = 0; i < data['otherpn'].length; i ++) {
                    var point = new BMap.Point(data['otherpn'][i].longitude, data['otherpn'][i].latitude);

                    var content = data['otherpn'][i]['dispatch_name']+","+data['otherpn'][i]['mobile']+"</br>位置时间："+data['otherpn'][i]['place_up_time'];
                    var marker = new BMap.Marker(point);
                    map.addOverlay(marker);
                    addClickHandler(content,marker);
                }
            }
        });
        setTimeout("pnroute()",30000);
    }
    pnRobRouteCounts();
    function pnRobRouteCounts() {
        $.ajax({
            type: "GET",
            async: true,
            url: "{:U('pnRobRouteCounts',array('order_id'=>$route['order_id']))}",
            dataType: "json",
            success: function(data) {
               // console.log(data);

                var dataotherpn = data['otherpn'];
                for (var i = 0; i < data['otherpn'].length; i ++) {
                    var point = new BMap.Point(data['otherpn'][i].longitude, data['otherpn'][i].latitude);

                    var content = data['otherpn'][i]['dispatch_name']+","+data['otherpn'][i]['mobile']+"</br>位置时间："+data['otherpn'][i]['place_up_time'];
                    var marker = new BMap.Marker(point);
                    map.addOverlay(marker);
                    addClickHandler(content,marker);
                }
            }
        });
    //    setTimeout("pnRobRouteCounts()",3000);
    }
    var opts = {
        width : 20,     // 信息窗口宽度
        height: 20,     // 信息窗口高度
        title : "跑客信息" , // 信息窗口标题
        enableMessage:true//设置允许信息窗发送短息
    };
    function addClickHandler(content,marker){
        marker.addEventListener("click",function(e){
            openInfo(content,e)}
        );
    }
    function openInfo(content,e){
        var p = e.target;
        var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
        var infoWindow = new BMap.InfoWindow(content,opts);  // 创建信息窗口对象
        map.openInfoWindow(infoWindow,point); //开启信息窗口
    }

</script>
</body>
</html>